var button = {
	options : {
		tooltip: "Fit All - Visualizza alla massima estensione",
		iconCls: "fit",
		pressed: false,
		control : new OpenLayers.Control.ZoomToMaxExtent(),
		id: "fitall"
	},
	create : function(options) {
		CWN2.base.map.addControl(options.control);
		return new GeoExt.Action(options);
	}
};

CWN2.ToolbarBuilder.itemDefs[button.options.id] = button;
var button = {
			options : {
				tooltip: "Pan",
				iconCls: "pan",
				enableToggle: true,
				pressed: true,
				control: new OpenLayers.Control.Navigation(),
				id:"pan",
				toggleGroup: "toolGroup"
			},
			create : function(options) {
				CWN2.base.map.addControl(options.control);
				return new GeoExt.Action(options);
			}

};

CWN2.ToolbarBuilder.itemDefs[button.options.id] = button;

var button = {
	options :
	{
		tooltip: "Vai alla Visualizzazione Successiva",
		iconCls: "zoomnext",
		disabled: true,
		//enableToggle: true,
		pressed: false,
		id: "zoomnext"
	},
	create : function(options) {
		// create a navigation history control
		var historyControl = null; 
		var controls = CWN2.base.map.getControlsByClass("OpenLayers.Control.NavigationHistory");
		if (controls.length === 0) {
			historyControl = new OpenLayers.Control.NavigationHistory();
			CWN2.base.map.addControl(historyControl);						
		} else {
			historyControl = controls[0];
		} 			
		options.control = historyControl.next;
		return new GeoExt.Action(options);
	}
};

CWN2.ToolbarBuilder.itemDefs[button.options.id] = button;

var button = {
	options : {
		tooltip: "Vai alla Visualizzazione Precedente",
		iconCls: "zoomprevious",
		//enableToggle: true,
		disabled: true,
		pressed: false,
		id: "zoomprevious"
	},
	create : function(options) {
		// create a navigation history control
		var historyControl = null; 
		var controls = CWN2.base.map.getControlsByClass("OpenLayers.Control.NavigationHistory");
		if (controls.length === 0) {
			historyControl = new OpenLayers.Control.NavigationHistory();
			CWN2.base.map.addControl(historyControl);						
		} else {
			historyControl = controls[0];
		} 			
		options.control = historyControl.previous;
		return new GeoExt.Action(options);
	}
};

CWN2.ToolbarBuilder.itemDefs[button.options.id] = button;

var button = {
	options: {
		tooltip: "Zoom Out",
		iconCls: "zoomout",
		enableToggle: true,
		pressed: false,
		control: new OpenLayers.Control.ZoomBox({
			out: true
		}),
		id: "zoomout",
		toggleGroup: "toolGroup"
	},
	create: function(options){
		CWN2.base.map.addControl(options.control);
		return new GeoExt.Action(options);
	}
};

CWN2.ToolbarBuilder.itemDefs[button.options.id] = button;

var button = {
	options :
	{
		tooltip: "Misure Lineari",
		iconCls: "measureline",
		enableToggle: true,
		pressed: false,
		control : new OpenLayers.Control.Measure(OpenLayers.Handler.Path, {
			persist: true,
			eventListeners: {
				measure: function(evt){
					var out = '';
					out += 'Distanza: ' + evt.measure.toFixed(3) + " " + evt.units;
					Ext.getCmp("bbar_measure").setText(out);
				},
				measurepartial: function(evt){
					var out = '';
					out += 'Distanza: ' + evt.measure.toFixed(3) + " " + evt.units;
					Ext.getCmp("bbar_measure").setText(out);
				}
			}
		}),
		id: "measureline",
		toggleGroup: "toolGroup"

	},
	create : function(options) {
		CWN2.base.map.addControl(options.control);
		
		// aggiungo alla statusbar il campo per la visualizzazione delle misure
		if (!Ext.getCmp("bbar_measure")) {
			var item = {
				id: 'bbar_measure',
				text: "",
				width: 200,
				xtype: "tbtext"
			};
			Ext.getCmp("statusbar").add(item);
		}
		return new GeoExt.Action(options);
	}
};

CWN2.ToolbarBuilder.itemDefs[button.options.id] = button;


var button = {
			options : {
				tooltip: "Zoom In",
				iconCls: "zoomin",
				enableToggle: true,
				pressed: false,
				control : new OpenLayers.Control.ZoomBox(),
				id: "zoomin",
				toggleGroup: "toolGroup"
			},
			create : function(options) {
				CWN2.base.map.addControl(options.control);
				return new GeoExt.Action(options);
			}
};

CWN2.ToolbarBuilder.itemDefs[button.options.id] = button;

var button = {
	options : {
		id:"help",
		tooltip: "Help",
		iconCls: "help",
		pressed: false,
		handler: function(){
			// rendo visibile la finestra dell'help
	        Ext.getCmp("help-win").show();
	    }
	},
	create : function(options) {
		return new GeoExt.Action(options);
	}
};

CWN2.ToolbarBuilder.itemDefs[button.options.id] = button;

var button = {
	options :
	{
		tooltip: "Misure Areali",
		iconCls: "measurearea",
		enableToggle: true,
		pressed: false,
		control: new OpenLayers.Control.Measure(OpenLayers.Handler.Polygon, {
			persist: true,
			eventListeners: {
				measure: function(evt){
					var out = '';
					out += 'Area: ' + evt.measure.toFixed(3) + " " + evt.units + "2";
					Ext.getCmp("bbar_measure").setText(out);
				},
				measurepartial: function(evt){
					var out = '';
					out += 'Area: ' + evt.measure.toFixed(3) + " " + evt.units + "2";
					Ext.getCmp("bbar_measure").setText(out);
				}
			}
		}),
		id: "measurearea",
		toggleGroup: "toolGroup"

	},
	create : function(options) {
		CWN2.base.map.addControl(options.control);
		
		// aggiungo alla statusbar il campo per la visualizzazione delle misure
		if (!Ext.getCmp("bbar_measure")) {
			var item = {
				id: 'bbar_measure',
				text: "",
				width: 200,
				xtype: "tbtext"
			};
			Ext.getCmp("statusbar").add(item);
		}
		
		return new GeoExt.Action(options);
	}
};

CWN2.ToolbarBuilder.itemDefs[button.options.id] = button;

